package com.radar.RadarOnline;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainMenu extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView tv = new TextView(this);
		// tv.setText("Hello World!");
		// setContentView(tv);
		try {
			URL url = new URL("http://www.radaronline.com/feed");

			/* Get a SAXParser from the SAXPArserFactory. */
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();

			/* Get the XMLReader of the SAXParser we created. */
			XMLReader xr = sp.getXMLReader();

			/* Create a new ContentHandler and apply it to the XML-Reader */
			ExampleHandler myExampleHandler = new ExampleHandler();
			xr.setContentHandler(myExampleHandler);

			/* Parse the xml-data from our URL. */
			xr.parse(new InputSource(url.openStream()));
			/* Parsing has finished. */

			/* Our ExampleHandler now provides the parsed data to us. */
			ParsedExampleDataSet parsedExampleDataSet = myExampleHandler
					.getParsedData();

			/* Set the result to be displayed in our GUI. */
			tv.setText(parsedExampleDataSet.toString());

		} catch (Exception e) {
			tv.setText("Error: " + e.getMessage());
			// Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
		}
	}

}
